package com.nwpu.bigdata.controller;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.nwpu.bigdata.dto.PodInfo;
import com.nwpu.bigdata.dto.SoftwareStatus;
import com.nwpu.bigdata.service.PodInfoService;
import com.nwpu.bigdata.util.KubernetesUtil;

import io.fabric8.kubernetes.client.KubernetesClient;

/**
 *@version:2018年6月4日上午8:31:29
*/
/**
 * @author Administrator
 *
 */
@Controller//标识他是一个控制器
@RequestMapping("/podInfo")
public class PodInfoController {
@Autowired
private PodInfoService podInfoService;
@Autowired
private KubernetesUtil kubernetesUtil;
	@RequestMapping(value="/software/status", method={RequestMethod.GET}, produces="application/json;charset=UTF-8")
	public @ResponseBody List<SoftwareStatus> podInfo(ModelAndView modelAndView) throws Exception {
		
		KubernetesClient kubernetesClient = kubernetesUtil.connectK8s();
		List<SoftwareStatus> list = podInfoService.getPodInfoList(kubernetesClient);
		
		
		return list;
	}
	@RequestMapping(value="/cassandra/list", method={RequestMethod.GET}, produces="application/json;charset=UTF-8")
	public @ResponseBody List<PodInfo> cassandraPods(ModelAndView modelAndView) throws Exception {
		
		KubernetesClient kubernetesClient = kubernetesUtil.connectK8s();
		List<PodInfo> list = podInfoService.getSoftwarePod(kubernetesClient, "kvstore");
		
		
		return list;
	}
	@RequestMapping(value="/neo4j/list", method={RequestMethod.GET}, produces="application/json;charset=UTF-8")
	public @ResponseBody List<PodInfo> neo4jPods(ModelAndView modelAndView) throws Exception {
		
		KubernetesClient kubernetesClient = kubernetesUtil.connectK8s();
		List<PodInfo> list = podInfoService.getSoftwarePod(kubernetesClient, "ingraphdb");
		
		
		return list;
	}
	
	@RequestMapping(value="/iotdb/list", method={RequestMethod.GET}, produces="application/json;charset=UTF-8")
	public @ResponseBody List<PodInfo> iotdbPods(ModelAndView modelAndView) throws Exception {
		
		KubernetesClient kubernetesClient = kubernetesUtil.connectK8s();
		List<PodInfo> list = podInfoService.getSoftwarePod(kubernetesClient, "iotdb");
		
		
		return list;
	}
	@RequestMapping(value="/mysql/list", method={RequestMethod.GET}, produces="application/json;charset=UTF-8")
	public @ResponseBody List<PodInfo> mysqlPods(ModelAndView modelAndView) throws Exception {
		
		KubernetesClient kubernetesClient = kubernetesUtil.connectK8s();
		List<PodInfo> list = podInfoService.getSoftwarePod(kubernetesClient, "kingbase");
		
		
		return list;
	}
	@RequestMapping(value="/unstructured/list", method={RequestMethod.GET}, produces="application/json;charset=UTF-8")
	public @ResponseBody List<PodInfo> unstructuredPods(ModelAndView modelAndView) throws Exception {
		
		KubernetesClient kubernetesClient = kubernetesUtil.connectK8s();
		List<PodInfo> list = podInfoService.getSoftwarePod(kubernetesClient, "unstructfs");
		
		
		return list;
	}
}
